﻿/*
This file is part of Claymore.
Copyright (C) 2009, Fabrice Michellonet (fabrice dot michellonet at gmail dot com)

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

using System.Reflection;

namespace Claymore
{
    public partial class Claymore
    {

        #region Fields

        private static Config _config;

        #endregion

        /// <summary>
        /// Hide the default constructor.
        /// </summary>
        private Claymore()
        {
        }

        /// <summary>
        /// Gets the view manager.
        /// </summary>
        /// <value>The view manager.</value>
        public static IViewManager ViewManager
        {
            get { return _config.GetViewManager(); }
        }

        /// <summary>
        /// Gets the presenter manager.
        /// </summary>
        /// <value>The presenter manager.</value>
        public static IPresenterManager PresenterManager
        {
            get { return _config.GetPresenterManager(); }
        }

        /// <summary>
        /// Initializes Claymore engine.
        /// </summary>
        public static IClaymoreConfigElement Initialize()
        {
            if(_config == null)
                _config = new Config();

            _config
                .SetViewManager(new ClaymoreViewManager())
                .SetPresenterManager(new ClaymorePresenterManager());

            return Initialize(Assembly.GetCallingAssembly());
        }

        /// <summary>
        /// Initializes Claymore engine using the specified assembly.
        /// </summary>
        /// <param name="asm">The asm.</param>
        private static Config Initialize(Assembly asm)
        {
            _config.ViewManager.AddViewsAssembly(asm);
            _config.PresenterManager.AddPresentersAssembly(asm);

            return _config;
        }
    }
}